---
apiVersion: v1
kind: Service
metadata:
  name: minio
  namespace: kubesphere-system
  labels:
    app: kubesphere
    tier: minio
spec:
  selector:
    app: kubesphere
    tier: minio
  ports:
  - name: tcp
    protocol: TCP
    port: 9000
    targetPort: 9000


---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: minio-pvc
  namespace: kubesphere-system
  labels:
    app: kubesphere
    tier: minio
spec:
  accessModes:
    - ReadWriteOnce
{% if persistence.storageClass is defined and persistence.storageClass != "" %}
  storageClassName: {{ persistence.storageClass }}
{% endif %}
  resources:
    requests:
      storage: {{ common.minioVolumeSize }}
{% if minio_pv_name is defined and minio_pv_name != None %}
  volumeName: {{ minio_pv_name }}
{% endif %}


---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: minio
  namespace: kubesphere-system
  labels:
    app: kubesphere
    tier: minio
spec:
  selector:
    matchLabels:
      app: kubesphere
      tier: minio
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: kubesphere
        tier: minio
    spec:
      containers:
      - name: minio
        image: {{ minio_repo }}:{{ minio_tag }}
        imagePullPolicy: IfNotPresent
        lifecycle:
          postStart:
            exec:
              command: ["sh", "-c", "mkdir -p /data/openpitrix-attachment /data/openpitrix-internal-repo/vmbased /data/openpitrix-internal-repo/helm /data/s2i-binaries"]
        args:
          - server
          - /data
        env:
        - name: MINIO_ACCESS_KEY
          value: "openpitrixminioaccesskey"
        - name: MINIO_SECRET_KEY
          value: "openpitrixminiosecretkey"
        ports:
        - containerPort: 9000
          name: minio
        volumeMounts:
        - name: minio-persistent-storage
          mountPath: /data
      volumes:
      - name: minio-persistent-storage
        persistentVolumeClaim:
          claimName: minio-pvc
